package study.transaction.atomikos.support.transaction;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.TransactionManager;

import javax.annotation.PostConstruct;
/**
 * （1）自动装配
 * （2）自定义
 */
@Slf4j
@Configuration
public class TransactionManagerConfig {

    @Autowired
    public TransactionManager transactionManager;

    @PostConstruct
    public void init() {
        log.info(">>>>>>");
        log.info(">>>>>> {}", transactionManager.getClass().getSimpleName());
        log.info(">>>>>>");
    }

    /**
     * 事务管理器
     */
//    @Bean
//    public JtaTransactionManager transactionManager() throws Exception {
//        //
//        UserTransaction userTransaction = new UserTransactionImp();
//        userTransaction.setTransactionTimeout(1);
//        //
//        UserTransactionManager userTransactionManager = new UserTransactionManager();
//        userTransactionManager.setForceShutdown(false);
    //配置spring的JtaTransactionManager，底层委派给atomikos进行处理
//        return new JtaTransactionManager(userTransaction, userTransactionManager);
//    }
}
